function openFile(file) {
    var component = Qt.createComponent(file)
    if (component.status === Component.Ready)
        pageStack.push(component);
    else
        console.log("Error replace component:", component.errorString());
}

function switchFile(file) {
    var loadPage = Qt.createComponent(file)
    if (loadPage.status === Component.Ready){
        pageStack.replace(loadPage);
    }else
        console.log("Error loading component:", loadPage.errorString());
}

function exitApp(){
    Qt.quit();
}

function findPage(target){
    return pageStack.find(function(page){
                              return page.pageTarget === target;
                          }
                     );
}

function backToPage(target){
    pageStack.pop(pageStack.find(function(page){
                     return page.pageTarget === target;
                 }
            ))
}

function back(){
    pageStack.pop();
}

// 服务器获取xml数据
function getXmlStringByUrl(url, callback){
    var doc = new XMLHttpRequest();
    doc.onreadystatechange = function() {
        if (doc.readyState == XMLHttpRequest.HEADERS_RECEIVED) {
        } else if (doc.readyState == XMLHttpRequest.DONE) {
            callback(doc.responseXML);
        }
    }
    doc.open("GET", url);
    doc.send();
}
